public class Solution1 {
    //最长公共前缀
    public String longestCommonPrefix(String[]strs){
        if(strs==null||strs.length==0){
    return " ";
        }

        String prefix=strs[0];
        for (int i=1;i<strs.length;i++){
            while (strs[i].indexOf(prefix)!=0){
                prefix=prefix.substring(0,strs.length-1);

                if (prefix.isEmpty()){
                    return " ";
                }
            }
        }
        return prefix;

    }

    public static void main(String[] args) {
        Solution1 solution1=new Solution1();
        String[]strs1={"flower", "flow", "flight"};
        System.out.println(solution1.longestCommonPrefix(strs1));
        String[]strs2={"dog", "racecar", "car"};
        System.out.println(solution1.longestCommonPrefix(strs2));


    }
}
